﻿window.tsyntax = new (function () {
    var self = this;
    var wscript = function (src, type) {
        document.write('<script src="' + src + '" type="' + (type || 'text/javascript') + '"></script>');
    };
    var wlink = function (href, rel, type) {
        document.write('<link href="' + href + '" rel="' + (rel || 'stylesheet') + '" type="' + (type || 'text/css') + '"/>');
    };
    self.startup = function () {
        var newLine = '\r\n';
        hljs.tabReplace = '    ';
        jQuery('blockquote[tsyntax]').each(function () {
            var $blockquote = jQuery(this);
            $blockquote.find('br').replaceWith(newLine);
            $blockquote.find('p').each(function () {
                var $p = jQuery(this);
                $p.replaceWith($p.text() + newLine);
            });
            var $code = jQuery('<code>').html($blockquote.html().replace(/&nbsp;/gi, ' ')).addClass($blockquote.attr('tsyntax'));
            $blockquote.replaceWith(jQuery('<pre>').html($code));
        });
        hljs.initHighlighting();
    };
    wlink('http://softwaremaniacs.org/media/soft/highlight/styles/vs.css');
    wscript('http://ajax.aspnetcdn.com/ajax/jquery/jquery-1.8.0.min.js');
    wscript('http://softwaremaniacs.org/media/soft/highlight/highlight.pack.js');
    document.write('<script type="text/javascript">jQuery(tsyntax.startup);</script>');
})();